<?php
namespace PsiFramework\Applications\eCoaching\Classes\Actions;

use PsiFramework\Classes\Util\Security\Manager\SecurityManager;

use PsiFramework\Classes\Factory\ObjectFactory;

use PsiFramework\Classes\Factory\DAOFactory;

use PsiFramework\Applications\DefaultApp\Classes\Actions\User\RegisterAction;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The Register Action
 *
 * This action is used when a user wants to create an account
 *
 * @package Actions.User
 */
class ECoachingRegisterAction extends RegisterAction
{
    /**
     * (non-PHPdoc)
     * @see PsiFramework\Applications\DefaultApp\Classes\Actions\User.RegisterAction::afterCreation()
     */
    public function afterCreation($user) {
        $roleDao = DAOFactory::getDAO('SecurityRole');
        $securityRole = $roleDao->getRoleByName('e-coaching_user', false);
        
        $userRoleDao = DAOFactory::getDAO('SecurityUserRole');
        
        $userRole = ObjectFactory::getNewObject('SecurityUserRole');
        $userRole->setUser($user);
        $userRole->setRole($securityRole);
        
        return $userRoleDao->save($userRole, true, false);
    }
    
    /**
     * (non-PHPdoc)
     * @see PsiFramework\Applications\DefaultApp\Classes\Actions\User.RegisterAction::getUserParameters()
     */
    public function getUserParameters(&$user) {
        $user->setActivated(true);
        
        return true;
    }
}
